package cn.silver.framework.mybatis.bean;

import cn.silver.framework.core.model.DictModel;
import cn.silver.framework.core.utils.DateUtils;
import cn.silver.framework.core.validate.AddGroup;
import cn.silver.framework.core.validate.EditGroup;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import jakarta.validation.constraints.Size;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.Date;

/**
 * @author zhouxiaobo
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode(callSuper = true)
@Schema(name = "BusModel", description = "业务对象模型")
public abstract class BusBean extends BaseBean {

    @Schema(title = "编码")
//    @NotBlank(message = "编码不能为空", groups = {AddGroup.class, EditGroup.class})
//    @Pattern(regexp = "[a-zA-Z0-9_:-]{1,32}", message = "编码只能包括数字、字母、下划线、短横线、冒号，且不超过32个字符", groups = {AddGroup.class, EditGroup.class})
    private String code;

    @Schema(title = "名称")
    @NotBlank(message = "名称不能为空", groups = {AddGroup.class, EditGroup.class})
    @Size(min = 2, max = 40, message = "名称必须在2-40个字符之间", groups = {AddGroup.class, EditGroup.class})
    private String name;

    @Schema(title = "状态")
    @NotBlank(message = "状态不能为空")
    private String status;

    @Schema(title = "排序")
    private Integer sort;

    @Schema(title = "备注说明")
    private String remark;

    @Schema(title = "创建单位")
    private String createDept;

    @Schema(title = "创建人")
    private String createBy;

    @Schema(title = "创建时间")
    @JsonFormat(timezone = DateUtils.TIME_ZONE, pattern = DateUtils.YYYY_MM_DD_HH_MM_SS)
    private Date createTime;

    @Schema(title = "更新人")
    private String updateBy;

    @Schema(title = "更新时间")
    @JsonFormat(timezone = DateUtils.TIME_ZONE, pattern = DateUtils.YYYY_MM_DD_HH_MM_SS)
    private Date updateTime;

    public DictModel convertDict() {
        return new DictModel(this.getId(), this.name, this.code, "", this.sort, this.remark);
    }
}
